package com.yehui.jdk.jdk11;

import java.util.Arrays;

/**
 * @author 业徽
 * @date 2021/8/23
 */
public class NestedClassDemo {

    public static void main(String[] args) {
        final NestedClass nestedClass = new NestedClassDemo().new NestedClass();
        nestedClass.nestedHello();

        System.out.println("NestedClassDemo.class.getNestHost(): " + NestedClassDemo.class.getNestHost());
        System.out.println("NestedClassDemo.class.getNestMembers(): " + Arrays.toString(NestedClassDemo.class.getNestMembers()));
        System.out.println("NestedClassDemo.class.isNestmateOf(NestedClassDemo.class): " + NestedClassDemo.class.isNestmateOf(NestedClassDemo.class));
        System.out.println("NestedClassDemo.class.isNestmateOf(NestedClass.class): " + NestedClassDemo.class.isNestmateOf(NestedClass.class));

        System.out.println("NestedClass.class.getNestHost(): " + NestedClass.class.getNestHost());
        System.out.println("NestedClass.class.getNestMembers(): " + Arrays.toString(NestedClass.class.getNestMembers()));
        System.out.println("NestedClass.class.isNestmateOf(NestedClassDemo.class): " + NestedClass.class.isNestmateOf(NestedClassDemo.class));
        System.out.println("NestedClass.class.isNestmateOf(NestedClass.class): " + NestedClass.class.isNestmateOf(NestedClass.class));
    }

    private void hello() {
        System.out.println(this.getClass().getName());
    }

    public class NestedClass {
        public void nestedHello() {
            System.out.println("nested hello, invoke host hello");
            hello();
        }
    }

}
